package dongwu;

public class AnimalTest {
    public static void main(String[] args) {
        // 创建Animal类型的数组，包含Dog和Cat //
        Animal[] animals = {
            new Dog("Miqi", 3, "Husky"),
            new Dog("Mixue", 5, "Labrador"),
            new Cat("Mianbao", 2, "Orange"),
            new Cat("Dousha", 1, "White")
        };

        // 遍历动物数组  //
        for (Animal animal : animals) {
            // 展示多态性  //
            animal.makeSound();

            // 检查是否实现了Swimmable  //
            if (animal instanceof Swimmable) {
                ((Swimmable) animal).swim();
            }

            // 检查是否实现了Trainable  //
            if (animal instanceof Trainable) {
                ((Trainable) animal).train();
            }

            System.out.println(); //  空行分隔  //
        }
    }
}
